package control
{
	import flash.display.DisplayObject;
	import flash.display.LineScaleMode;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.geom.Rectangle;

	public class CropFrame extends MovieClip
	{
		private var _cropFrame: MovieClip = new MovieClip
		private var _cropFrameRect: Rectangle
		private var _centeredTarget: DisplayObject
		
		public function CropFrame(width:Number=100, height:Number=100)
		{
			super();
			_cropFrameRect = new Rectangle(0, 0, width, height)

			_cropFrame.graphics.lineStyle(2, 0x0000FF, 0.9, true, LineScaleMode.NONE)
			_cropFrame.graphics.drawRect(0, 0, _cropFrameRect.width, _cropFrameRect.height)
			_cropFrame.graphics.lineStyle()
			addChild(_cropFrame)
			addEventListener(Event.ADDED_TO_STAGE, function ():void {init()}) 
		}
		
		private function init (): void {
		   stage.addEventListener(Event.RESIZE, function ():void {redraw()})
		   redraw()
		}
		
		public function get frameHeight (): Number {
			return _cropFrameRect.height
		}
		
		public function set frameHeight (value:Number): void {
			_cropFrameRect.height = value
			redraw()
		}

		public function get frameWidth (): Number {
			return _cropFrameRect.width
		}
		
		public function set frameWidth (value:Number): void {
			_cropFrameRect.width = value
			redraw()
		}
		
		private function redraw (): void {
			_cropFrame.x = (stage.stageWidth - _cropFrame.width) / 2
			_cropFrame.y = (stage.stageHeight - _cropFrame.height) / 2
			_cropFrame.width = _cropFrameRect.width
			_cropFrame.height = _cropFrameRect.height
		} 
		
	}
}